package chances.wechat.repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import chances.wechat.entity.PlayRecord;

@Repository
public class PlayRepository extends BaseRepository {

	public PlayRepository() {
		super();
		this.namespace = "weixin.interaction";
	}

	public void add(PlayRecord playRecord) {
		this.sqlSessionTemplate.insert("insertPlayRecord", playRecord);
	}

	public void remove(String stbNo) {
		this.sqlSessionTemplate.delete("deletePlayRecordByStbNo", stbNo);
	}

	public PlayRecord getPlayRecord(Long id) {
		return super.getOne("getPlayRecord", id);
	}

	public PlayRecord getPlayRecordByStbNo(String stbNo) {
		return super.getOne("getPlayRecordByStbNo", stbNo);
	}

	public List<PlayRecord> listPlayRecordByUserId(String userId) {
		return this.sqlSessionTemplate.selectList("listPlayRecordByUserId",
				userId);
	}

	public void insertPlayRecord(PlayRecord playRecord) {
		this.sqlSessionTemplate.insert("insertPlayRecord", playRecord);
	}

	public void updateRecord(PlayRecord playRecord) {
		this.sqlSessionTemplate.update("updatePlayRecord", playRecord);
	}
	
	public void deleteHistory(String userId,
			String[] codes) {
		String name = this.getName("deletePlayHistory");
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		params.put("codes", codes);
		
		this.sqlSessionTemplate.delete(name,params);
				
	}
}
